package com.lyy.mybatis.sensitive.secret;

import cn.hutool.crypto.SecureUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * 默认加密实现
 *
 * @author lyy 2024/11/23
 */
@Slf4j
public class Aes extends SecretAbstract {
    public static final byte[] AES_KEY = "A6BBD8739085CE89".getBytes();

    @Override
    public String encrypt(String str) {
        return SecureUtil.aes(AES_KEY).encryptBase64(str);
    }

    @Override
    public String encryptWithOutFlag(String str) {
        return encrypt(str);
    }

    @Override
    public String decrypt(String str) {
        try {
            return SecureUtil.aes(AES_KEY).decryptStr(str);
        } catch (Exception e) {
            log.warn("原文待解密信息:{},解密失败,将按照原文返回", str, e);
            return str;
        }
    }
}
